<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>应用配置</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="yaf.tutorials.html">« 范例</a></li>
      <li style="float: right;"><a href="class.yaf-application.html">Yaf_Application »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="book.yaf.html">Yaf</a></li>
    <li>应用配置</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="yaf.appconfig" class="chapter">
 <h1>应用配置</h1>

 <p class="para">
  你需要传递一个config数组或ini配置文件（参见
  <span class="classname"><a href="class.yaf-config-ini.html" class="classname">Yaf_Config_Ini</a></span>） 给
  <span class="methodname"><a href="yaf-application.construct.html" class="methodname">Yaf_Application::__construct()</a></span>. 
 </p>
 <p class="para">
  Yaf的配置文件会和用户的配置文件合并。区别在于，Yaf的配置文件是以&quot;yaf.&quot;或&quot;application.&quot;开头，如果两项都存在，则&quot;application.&quot;生效。
  <div class="example" id="example-3865">
   <p><strong>示例 #1 config为数组的例子</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />&nbsp;&nbsp;&nbsp;&nbsp;$configs&nbsp;</span><span style="color: #007700">=&nbsp;array(<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">"application"&nbsp;</span><span style="color: #007700">=&gt;&nbsp;array(<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">"directory"&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">dirname</span><span style="color: #007700">(</span><span style="color: #0000BB">__FILE__</span><span style="color: #007700">),<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">"dispatcher"&nbsp;</span><span style="color: #007700">=&gt;&nbsp;array(<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">"catchException"&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;),<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">"view"&nbsp;</span><span style="color: #007700">=&gt;&nbsp;array(<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">"ext"&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">"phtml"</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;),<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;),<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;);<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$app&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">Yaf_Application</span><span style="color: #007700">(</span><span style="color: #0000BB">$config</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

  </div>
  <div class="example" id="example-3866">
   <p><strong>示例 #2 config为ini文件的例子</strong></p>
   <div class="example-contents">
<div class="inicode"><pre class="inicode">[yaf]
yaf.directory = APPLICATION_PATH &quot;/appliation&quot;
yaf.dispatcher.catchException = 0

[product : yaf]
; user configuration list here</pre>
</div>
   </div>

  </div>
  </p>
  <p class="para">
  <table class="doctable table">
   <caption><strong>Yaf Application Config</strong></caption>
   
    <thead>
     <tr>
      <th>名字</th>
      <th>默认</th>
      <th>更新日志</th>
     </tr>

    </thead>

    <tbody class="tbody">
     <tr>
      <td>application.directory</td>
      <td class="empty">&nbsp;</td>
      <td></td>
     </tr>

     <tr>
      <td>application.ext</td>
      <td>&quot;php&quot;</td>
      <td></td>
     </tr>

     <tr>
      <td>application.view.ext</td>
      <td>&quot;phtml&quot;</td>
      <td></td>
     </tr>

     <tr>
      <td>application.modules</td>
      <td>&quot;index&quot;</td>
      <td></td>
     </tr>

     <tr>
      <td>application.library</td>
      <td>application.directory . &quot;/library&quot;</td>
      <td></td>
     </tr>

     <tr>
      <td>application.library.directory</td>
      <td>application.directory . &quot;/library&quot;</td>
      <td></td>
     </tr>

     <tr>
      <td>application.library.namespace</td>
      <td>&quot;&quot;</td>
      <td></td>
     </tr>

     <tr>
      <td>application.bootstrap</td>
      <td>application.directory . &quot;/Bootstrap&quot; . application.ext</td>
      <td></td>
     </tr>

     <tr>
      <td>application.baseUri</td>
      <td>&quot;&quot;</td>
      <td></td>
     </tr>

     <tr>
      <td>application.dispatcher.defaultRoute</td>
      <td class="empty">&nbsp;</td>
      <td></td>
     </tr>

     <tr>
      <td>application.dispatcher.throwException</td>
      <td>1</td>
      <td></td>
     </tr>

     <tr>
      <td>application.dispatcher.catchException</td>
      <td>0</td>
      <td></td>
     </tr>

     <tr>
      <td>application.dispatcher.defaultModule</td>
      <td>&quot;index&quot;</td>
      <td></td>
     </tr>

     <tr>
      <td>application.dispatcher.defaultController</td>
      <td>&quot;index&quot;</td>
      <td></td>
     </tr>

     <tr>
      <td>application.dispatcher.defaultAction</td>
      <td>&quot;index&quot;</td>
      <td></td>
     </tr>

     <tr>
      <td>application.system</td>
      <td class="empty">&nbsp;</td>
      <td></td>
     </tr>

    </tbody>
   
  </table>

 </p>

 <p class="para">这是配置指令的简短说明。</p>

 <p class="para">
  <dl>
   
     <dt id="configuration.yaf.directory">
      <code class="parameter">application.directory</code>
      <span class="type">string</span>
     </dt>

     <dd>

      <p class="para">
       应用程序的目录，包含&quot;controllers&quot;, &quot;views&quot;, &quot;models&quot;, &quot;plugins&quot;等子目录。
      </p>
      <p class="para">
       <blockquote class="note"><p><strong class="note">注意</strong>: 
        <p class="para">
         这是唯一一个没有默认值的配置项，你需要手动指定它。
        </p>
       </p></blockquote>
      </p>
     </dd>

    
    
     <dt id="configuration.yaf.ext">
      <code class="parameter">application.ext</code>
      <span class="type">string</span>
     </dt>

     <dd>

      <p class="para">
       PHP脚本的扩展名，类的自动加载需要用到它(
       <span class="classname"><a href="class.yaf-loader.html" class="classname">Yaf_Loader</a></span>)。
      </p>
     </dd>

    
    
     <dt id="configuration.yaf.view.ext">
      <code class="parameter">application.view.ext</code>
      <span class="type">string</span>
     </dt>

     <dd>

      <p class="para">
       视图模板扩展名。
      </p>
     </dd>

    
    
     <dt id="configuration.yaf.modules">
      <code class="parameter">application.modules</code>
      <span class="type">string</span>
     </dt>

     <dd>

      <p class="para">
        注册的模块列表，以逗号分隔，用于路由处理，特别是当PATH_INFO超过三段的时候， 
      </p>
      <p class="para">
        Yaf需要用它来判断第一段是否是一个模块。
      </p>
     </dd>

    
    
     <dt id="configuration.yaf.library">
      <code class="parameter">application.library</code>
      <span class="type">string</span>
     </dt>

     <dd>

      <p class="para">
        本地类库的目录，参见<span class="classname"><a href="class.yaf-loader.html" class="classname">Yaf_Loader</a></span> 和
       <a href="yaf.configuration.html#ini.yaf.library" class="link">yaf.library</a>。
       </p>
       <blockquote class="note"><p><strong class="note">注意</strong>: 
        <p class="para">
         Yaf2.1.6以后，该配置项也可以是一个数组，当它是数组的时候，类库的路径将尝试使用<a href="yaf.appconfig.html#configuration.yaf.library.directory" class="link">application.library.directory</a>的值。
        </p>
       </p></blockquote>
     </dd>

    
    
     <dt id="configuration.yaf.library.directory">
      <code class="parameter">application.library.directory</code>
      <span class="type">string</span>
     </dt>

     <dd>

      <p class="para">
       Alias of <a href="yaf.appconfig.html#configuration.yaf.library" class="link">application.library</a>. Introduced
       in Yaf 2.1.6
      </p>
     </dd>

    
    
     <dt id="configuration.yaf.library.namespace">
      <code class="parameter">application.library.namespace</code>
      <span class="type">string</span>
     </dt>

     <dd>

      <p class="para">
       逗号分隔的本地类库命名空间前缀。
      </p>
      <p class="para">
       Yaf2.1.6以后加入
      </p>
     </dd>

    
    
     <dt id="configuration.yaf.bootstrap">
      <code class="parameter">application.bootstrap</code>
      <span class="type">string</span>
     </dt>

     <dd>

      <p class="para">
       Bootstrap类脚本文件的绝对路径。
      </p>
     </dd>

    
    
     <dt id="configuration.yaf.baseuri">
      <code class="parameter">application.baseUri</code>
      <span class="type">string</span>
     </dt>

     <dd>

      <p class="para">
       路由处理中需要忽略的路径前缀。举个例子，请求&quot;/prefix/controller/action&quot;时。如果你将application.baseUri设置为&quot;/prefix&quot;，那么只有&quot;/controller/action&quot;会被当做路由路径。
      </p>
      <p class="para">
       通常不需要设置此值。 
      </p>
     </dd>

    
    
     <dt id="configuration.yaf.dispatcher.throwexception">
      <code class="parameter">application.dispatcher.throwException</code>
      <span class="type">bool</span>
     </dt>

     <dd>

      <p class="para">
       开启此项，Yaf会在发生错误的地方抛出异常。参见
       <span class="methodname"><a href="yaf-dispatcher.throwexception.html" class="methodname">Yaf_Dispatcher::throwException()</a></span>。
      </p>
     </dd>

    
    
     <dt id="configuration.yaf.dispatcher.catchexception">
      <code class="parameter">application.dispatcher.catchException</code>
      <span class="type">bool</span>
     </dt>

     <dd>

      <p class="para">
       开启此项，如果有未捕获的异常，Yaf将会把它定向到Error controller, Error Action。参见
       <span class="methodname"><a href="yaf-dispatcher.catchexception.html" class="methodname">Yaf_Dispatcher::catchException()</a></span>。
      </p>
     </dd>

    
    
     <dt id="configuration.yaf.dispatcher.defaulRoute">
      <code class="parameter">application.dispatcher.defaultRoute</code>
      <span class="type">string</span>
     </dt>

     <dd>

      <p class="para">
       默认路由，如果未指定，静态路由会被当做是默认路由，参见：
       <span class="methodname"><a href="yaf-router.addroute.html" class="methodname">Yaf_Router::addRoute()</a></span>。
      </p>
     </dd>

    
    
     <dt id="configuration.yaf.dispatcher.defaultmodule">
      <code class="parameter">application.dispatcher.defaultModule</code>
      <span class="type">string</span>
     </dt>

     <dd>

      <p class="para">
       默认模块名，参见
       <span class="methodname"><a href="yaf-dispatcher.setdefaultmodule.html" class="methodname">Yaf_Dispatcher::setDefaultModule()</a></span>。
      </p>
     </dd>

    
    
     <dt id="configuration.yaf.dispatcher.defaultcontroller">
      <code class="parameter">application.dispatcher.defaultController</code>
      <span class="type">string</span>
     </dt>

     <dd>

      <p class="para">
       默认控制器名，参见
       <span class="methodname"><a href="yaf-dispatcher.setdefaultcontroller.html" class="methodname">Yaf_Dispatcher::setDefaultController()</a></span>。
      </p>
     </dd>

    
    
     <dt id="configuration.yaf.dispatcher.defaultaction">
      <code class="parameter">application.dispatcher.defaultAction</code>
      <span class="type">string</span>
     </dt>

     <dd>

      <p class="para">
       默认动作名，参见
       <span class="methodname"><a href="yaf-dispatcher.setdefaultaction.html" class="methodname">Yaf_Dispatcher::setDefaultAction()</a></span>。
      </p>
     </dd>

    

    
     <dt id="configuration.yaf.system">
      <code class="parameter">application.system</code>
      <span class="type">string</span>
     </dt>

     <dd>

      <p class="para">
       在application.ini中设置Yaf运行时配置，如：
       <a href="yaf.configuration.html#ini.yaf.lowcase-path" class="link">application.system.lowcase_path</a>
       <blockquote class="note"><p><strong class="note">注意</strong>: 
        <p class="para">
        仅有PHP_INI_ALL配置项能这样设置
       </p>
       </p></blockquote>
      </p>
     </dd>

    

  </dl>

 </p>
</div>
</div></div></body></html>